package com.zyw.customcalendar.common.util;

import java.util.ArrayList;
import java.util.Map;
import com.zyw.customcalendar.R;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.TextView;

public class DialogItemAdapter extends BaseAdapter {
	
	class HolderView{
		TextView content;
		CheckBox checkbox;
	}
	
	private int resource;
	private Context context;
	private ArrayList<Map<String,Object>> tlist;
	
	public DialogItemAdapter(ArrayList<Map<String,Object>> tlist, 
			int resource, Context context){
		this.resource = resource;
		this.tlist = tlist;
		this.context = context;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return tlist.size();
	}

	@Override
	public Object getItem(int index) {
		// TODO Auto-generated method stub
		return tlist.get(index);
	}

	@Override
	public long getItemId(int index) {
		// TODO Auto-generated method stub
		return index;
	}

	@Override
	public View getView(int index, View view, ViewGroup viewGroup) {
		// TODO Auto-generated method stub
		HolderView holderView = null;
		if(view == null){
			holderView = new HolderView();
			view = LayoutInflater.from(context).inflate(resource, null);
			holderView.content = (TextView) view.findViewById(R.id.dialog_list_context);
			holderView.checkbox = (CheckBox) view.findViewById(R.id.dialog_list_check);
			view.setTag(holderView);
		}else
			holderView = (HolderView) view.getTag();
		//����ֵ
		Map<String,Object> map = tlist.get(index);
		String content = (String) map.get("dialog_list_context");
		boolean checked = (boolean) map.get("dialog_list_check");
		holderView.content.setText(content);
		holderView.checkbox.setChecked(checked);
		return view;
	}

}
